package com.wn.system;

import cn.hutool.core.lang.hash.Hash;
import com.wn.common.utils.JwtTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yellow Docter
 * @date 2023 -07-21
 * @desc
 */
public class App {

    public static void main(String[] args) {

//        // spring  security 提供的加密工具
//        PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//
//        //加密
//        String encode = passwordEncoder.encode("123");
//        System.out.println("encode = " + encode);
//
//        //校验
//        //第一个参数是: 原始密码      (前端页面传递过来的)
//        //第二个参数是: 加密后的密码 （存储在 MySQL中）
//        boolean matches = passwordEncoder.matches("123", encode);
//        System.out.println("matches = " + matches);


        JwtTemplate jwtTemplate = new JwtTemplate();
        Map<String,Object> map = new HashMap<>();

        map.put("USER_ID","123");
        map.put("USER","123456");
        String token = jwtTemplate.createToken(map);

        System.out.println("token = " + token);

        boolean verify = jwtTemplate.verify(token);
        System.out.println("verify = " + verify);

        Object user = jwtTemplate.getPayload(token, "USER");
        System.out.println("user = " + user);

//        Object USER_ID = jwtTemplate.getPayload(token, "USER_ID");
//        System.out.println("USER_ID = " + USER_ID);

        String s = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJQSE9ORSI6IjE4NTY2MjMwMTM5IiwiVVNFUl9JRCI6MTY4MzMxMzg0NTIyOTYxNzE1NH0.9Gss4rSBM7Ok_q83HDfmfAT7EdZFPz52wuKAj9jncIk";

        String USER_ID = (String) jwtTemplate.getPayload(s, "USER_ID");
        System.out.println("USER_ID = " + USER_ID);
    }

}
